import pytest
import requests
from jsonpath import jsonpath

from api_test_framework.utils.handle_logger import init_logger

# 初始化日志配置
init_logger()


@pytest.fixture()
def setup_login():
    url_login = "http://shop.xxxxxban.com:8107/login"
    param = {"principal": "xxxxx_py", "credentials": "12345678", "appType": 3, "loginType": 0}
    response = requests.request('post', url=url_login, json=param)
    access_token = response.json()['access_token']
    access_token = jsonpath(response.json(), "$..access_token")[0]
    token_type = jsonpath(response.json(), '$..token_type')[0]
    token = token_type + access_token
    print(access_token)
    yield token
